from OpenGL.GL import *
from OpenGL.GLU import *
import gtk.gtkgl.apputils

# Ogl Canvas. The following variables are available:
# Have fun!
def i():
    light_ambient = [0.0, 0.0, 0.0, 1.0]
    light_diffuse = [1.0, 1.0, 1.0, 1.0]
    light_specular = [1.0, 1.0, 1.0, 1.0]
    # light_position is NOT default value
    light_position = [1.0, 1.0, 1.0, 0.0]

    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular)
    glLightfv(GL_LIGHT0, GL_POSITION, light_position)

    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_DEPTH_TEST)

def d(wigth,heigth):
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glPushMatrix()
    glRotatef(20.0, 1.0, 0.0, 0.0)
    glPushMatrix()
    glTranslatef(-0.75, 0.5, 0.0);
    glRotatef(90.0, 1.0, 0.0, 0.0)
    gtk.gdkgl.draw_torus(True, 0.275, 0.85, 15, 15)
    glPopMatrix()

    glPushMatrix()
    glTranslatef(-0.75, -0.5, 0.0);
    glRotatef(270.0, 1.0, 0.0, 0.0)
    gtk.gdkgl.draw_cone(True, 1.0, 2.0, 15, 15)
    glPopMatrix()

    glPushMatrix()
    glTranslatef(0.75, 0.0, -1.0)
    gtk.gdkgl.draw_sphere(True, 1.0, 15, 15)
    glPopMatrix()
    glPopMatrix()
    
def r(width,height):
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)

    glLoadIdentity()
    if width <= height:
        glOrtho(-2.5, 2.5, -2.5*height/width,2.5*height/width, -10.0, 10.0)
    else:
        glOrtho(-2.5*width/height,2.5*width/height, -2.5, 2.5, -10.0, 10.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

INIT = i
DISPLAY = d
RESHAPE = r



